package com.daocao.hua.view;

import android.app.*;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.daocao.hua.R;
import com.daocao.hua.util.Util;

import java.util.Calendar;

/**
 * Created by xsooy-pc on 2017/9/27.
 */

public class TimeViewDialog extends android.app.Dialog {
    private TimeView timeview;
    private Calendar calendar;
    private TextView txtContent;

    public TimeViewDialog(@NonNull Context context) {
        super(context, R.style.DialogStyle);
        init(context);
    }

    private void init(Context context) {
        View view = LayoutInflater.from(context)
                .inflate(R.layout.dialog_sign, null);
        setContentView(view);
        setCancelable(false);
        timeview = (TimeView) view.findViewById(R.id.time_view);
        txtContent = (TextView) view.findViewById(R.id.txt_content);
        calendar = Calendar.getInstance();
        long time = calendar.getTimeInMillis();
        timeview.setTime(time, 20, new Integer[]{1, 3, 8, 10, 20}, 20);
        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        Window mWindow = getWindow();
        mWindow.setGravity(Gravity.CENTER_VERTICAL);
        WindowManager.LayoutParams lp = mWindow.getAttributes();
        int heightDialog = Util.getDisplayMetrics(context).heightPixels;
//        lp.y = (int) (heightDialog * 0.2);
        lp.width = Util.getDisplayMetrics(context).widthPixels;
        lp.height = (int) (heightDialog);
        mWindow.setAttributes(lp);
    }

    public void setTime(Integer[] days) {
        if (days != null && days.length != 0) {
            int today = days[days.length - 1];
            timeview.setTime(calendar.getTimeInMillis(), today, days, today);
        } else {
            int today = -1;
            timeview.setTime(calendar.getTimeInMillis(), today, null, today);
        }
    }

    public void setTxtContent(String content) {
        txtContent.setText(content);
    }

}
